package routers

import (
	"github.com/gin-gonic/gin"
	"sport_booking/config"
	"sport_booking/controller"
	"sport_booking/middleware"
)

func SetupRouter() *gin.Engine {
	gin.SetMode(config.ServerMode)
	router := gin.Default()
	router.NoMethod(middleware.NotFount())
	router.NoRoute(middleware.NotFount())
	router.Use(middleware.Cors())
	api := router.Group("api")
	{
		// 注册
		api.POST("user/register/code", controller.SendRegisterAuthCodeByJSON)
		api.POST("user/register", controller.UserRegisterByJSON)
		// 登录
		api.POST("user/login", controller.UserLoginByJSON)
		// 重置密码
		api.POST("user/reset/code", controller.SendResetPasswordCodeByJSON)
		api.POST("user/reset", controller.ResetPasswordByJSON)

		// 获取最新活动信息
		api.GET("activity", controller.GetNewActivityOneInfo)
	}

	admin := router.Group("api")
	admin.Use(middleware.JwtAuthMiddleware(), middleware.AuthUserRoleMiddleware())
	{
		// 添加活动
		admin.POST("activity/add", controller.AddActivityInfo)
		// 修改活动
		admin.PUT("activity", controller.UpdateActivityInfo)
		// 获取部分活动
		admin.GET("activity/part", controller.GetActivityInfoByUUID)
		admin.GET("activity/part/all", controller.GetActivityInfoAll)
		// 获取所有活动
		//admin.GET("activity", controller.GetActivityAllByUUID)
		//admin.GET("activity/all", controller.GetActivityAll)
	}

	auth := router.Group("api")
	auth.Use(middleware.JwtAuthMiddleware())
	{
		// 完善用户信息
		auth.PUT("user/perfect", controller.PerfectUserInfoByJSON)

		// 参与活动
		auth.POST("join", controller.AddJoinInfo)
		// 修改参与活动状态
		auth.PUT("join", controller.UpdateJoinState)
		// 查看活动参与状态列表
		auth.GET("join", controller.GetJoinInfoList)

		// 获取第一级省市列表
		auth.GET("province", controller.GetOneProvince)
		// 获取其他城市列表
		auth.GET("city", controller.GetOtherCity)
	}
	return router
}
